package nc.ui.hljt.h00004;

import nc.ui.ic.pub.tools.GenMethod;
import nc.ui.pub.ButtonObject;
import nc.ui.pub.ToftPanel;
import nc.ui.pub.bill.BillCardPanel;
import nc.ui.pub.bill.BillEditEvent;
import nc.ui.pub.bill.BillListPanel;
import nc.ui.querytemplate.QueryConditionDLG;
import nc.ui.scm.plugin.IUIPluginToftPanel;
import nc.ui.scm.plugin.UIPluginFactory;
import nc.vo.hljt.h00004.Bill55Const;
import nc.vo.hljt.h00004.SApplyBillVO;
import nc.vo.ic.pub.ICConst;
import nc.vo.pub.AggregatedValueObject;
import nc.vo.pub.BusinessException;

public class ICPluginUI implements IUIPluginToftPanel {
	private ClientUI clientui;

	private ButtonObject[] m_btns;

	public ICPluginUI(ClientUI ui) {
		
		this.clientui = ui;
	}

	public void callAfterEdit(BillEditEvent e) {
		
		this.clientui.afterEdit(e);
	}

	public void callOnButtonClicked(ButtonObject bo) {
		
		this.clientui.onButtonClicked(bo);
	}

	public ButtonObject getButton(String btncode) {
		
		return UIPluginFactory.getIntance().findButtonObject(
				getClientui().getButtons(), btncode);
	}

	public BillCardPanel getCardPanel() {
		
		return getClientui().getBillCardPanel();
	}

	public BillListPanel getListPanel() {
		
		return getClientui().getBillListPanel();
	}

	public QueryConditionDLG getQueryDlg(BillEditEvent e) {
		
		return getClientui().getClientEventHandler().getQueryDlg();
	}

	public ToftPanel getToftPanel() {
		
		return getClientui();
	}

	public int getUIOperateState() {
		
		return getClientui().getBillOperate();
	}

	public int getUIShowState() {
		
		if (getClientui().isListPanelSelected())
			return nc.vo.scm.constant.ic.BillMode.List;
		else
			return nc.vo.scm.constant.ic.BillMode.Card;
	}

	public void onAddNewBillToUI(String biztype, AggregatedValueObject[] billvos)
			throws BusinessException {
		
		try {
			getClientui().getClientEventHandler().onAddVos((SApplyBillVO[])billvos);
		} catch (Exception e) {
			throw GenMethod.handleException(null, null, e);
		}
	}

	public void setBillVOsToUI(AggregatedValueObject[] billvos) {
		

	}

	public ClientUI getClientui() {
		return clientui;
	}

	public ButtonObject[] getExtBtns(ButtonObject[] bts) {
		if (m_btns == null) {
			m_btns = UIPluginFactory.getIntance().initUIFoctoryMenus(
					ICConst.MODULE_IC, Bill55Const.cbilltype, bts);
		}
		return m_btns;
	}

}
